package com.sky.mapper.common;

import com.github.pagehelper.Page;
import com.sky.aop.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {


    Page<SetmealVO> findByPage(String name, Integer categoryId, Integer status);

    @Insert("insert into setmeal values (null,#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image},#{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{makeTime})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id" )
    @AutoFill(OperationType.INSERT)
    void save(Setmeal setmeal);

    //@Select("select * from setmeal left join category on setmeal.category_id = category.id   where setmeal.id = #{id}")
    SetmealVO findById(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);


    void deleteByIds(@Param("ids") Long[] ids);

    @Update("update setmeal set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);


    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);


    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

}
